package contegor.scire.core.queries;

import java.util.Set;

import contegor.scire.core.Concept;
import contegor.scire.core.Container;
import contegor.scire.core.Id;
import contegor.scire.core.Link;
import contegor.scire.core.TaskId;
import contegor.scire.core.Version;

/**
 * {@link Query} that only extracts the {@link Link} instances that are in the target {@link Container}
 * and who's targets are the {@link Concept}s with the {@link Id}s given to the constructor.
 *
 * @version $Revision: 1.2 $
 * @author  Héctor Cirbián Pousa ($Author: hector $)
 */
@Version("$Id$")
public class GetLinksFromContainerAimingIds extends Query<Link> {
  private static final long serialVersionUID = 8564565803578562376L;

  private Id[] ids;

  GetLinksFromContainerAimingIds(TaskId taskId, Id targetContainerId, Id ... ids) {
    super(taskId, targetContainerId);
    this.ids = ids;
  }

  public void process(Container targetContainer) {
    for (Id id: ids) {
      Set<Link> links = targetContainer.getLinksReferring(id);
      if ((links != null) && (links.size() > 0))
        for (Link link: links)
          if (link.isVisibleTo(this.taskId.getTransactionId()))
            this.returnPoint.manage(this.taskId, link);
    }
  }
}
